<template>
  <div>
    <div class="address">
      <div>
        <p>您当前所在位置</p>
        <router-link to="/" class="link">新建售后单-面料</router-link>
      </div>
    </div>
    <div class="roder-details">
      <div class="info">
        <h3 class="title">订单信息</h3>
        <div class="list">
          <div class="list-div">
            <div>
              <p>订单编号</p>
              <span>{{ fabricOrderDetail.orderSn }}</span>
            </div>
            <div>
              <p>门店编号</p>
              <span>{{ fabricOrderDetail.storeCode }}</span>
            </div>
            <div>
              <p>创建时间</p>
              <span>{{ fabricOrderDetail.createTime }}</span>
            </div>

            <div>
              <p>订单金额</p>
              <span>{{ fabricOrderDetail.orderMoney }}元</span>
            </div>
            <!--                        <div>
                                        <p>快递方式</p>
                                        <span>{{fabricOrderDetail.courierName}}</span>
                                    </div>
                                    <div>
                                        <p>包装方式</p>
                                        <span>{{fabricOrderDetail.packaging}}</span>
                                    </div>
                                    <div>
                                        <p>地址类型</p>
                                        <span>{{fabricOrderDetail.addressType}}</span>
                                    </div>-->
            <div>
              <p>收货人</p>
              <span>{{ fabricOrderDetail.name }}</span>
            </div>
            <div>
              <p>收货电话</p>
              <span>{{ fabricOrderDetail.phone }}</span>
            </div>
            <div>
              <p>收货地址</p>
              <span>{{ fabricOrderDetail.address }}</span>
            </div>

          </div>

        </div>

        <h3 class="title">面料信息</h3>
        <div class="list" v-for="(item,key) in cartDeatil" :key="item.id">
          <div class="list-div">
            <div>
              <p>面料编号</p>
              <span>{{ item.fabricInfo.fabricCode }}</span>
            </div>
            <!--                        <div>
                                        <p style="justify-content: center;padding-left: 0px;">供应商面料编号</p>
                                        <span>UIIUING001</span>
                                    </div>-->
            <div>
              <p>面料成分</p>
              <span>{{ item.fabricInfo.fabricContent }}</span>
            </div>

            <div>
              <p>面料纱支</p>
              <span>{{ item.fabricInfo.fabricShazhi }}</span>
            </div>
            <div>
              <p>面料克重</p>
              <span>{{ item.fabricInfo.fabricWeight }}g</span>
            </div>
            <!--                        <div>
                                        <p>花型</p>
                                        <span>人字</span>
                                    </div>-->
            <div>
              <p>颜色</p>
              <span>{{ item.fabricInfo.color }}</span>
            </div>
            <div>
              <p>样本</p>
              <span>{{ item.fabricInfo.fabricSample }}</span>
            </div>
            <div>
              <p>幅宽</p>
              <span>{{ item.fabricInfo.fabricWidth }}cm</span>
            </div>
            <div>
              <p>门幅</p>
              <span>{{ item.fabricInfo.menfu }}</span>
            </div>
            <div>
              <p>季节</p>
              <span>{{ item.fabricInfo.season }}</span>
            </div>
          </div>
          <div>
            <p></p>
            <label>
              <p>备注信息：</p>
              <el-input type="textarea" style="width:400px" :autosize="{ minRows: 2, maxRows: 4}" disabled
                        :value="item.remark"></el-input>
            </label>
          </div>
        </div>

        <h3 class="title">售后原因</h3>
        <a-select v-model="afterType" style="width: 120px">
          <a-select-option value="0">
            退货
          </a-select-option>
          <a-select-option value="1">
            换货
          </a-select-option>

        </a-select>

        <label>
          选择产品：
          <a-select placeholder="选择产品" v-model="cart" style="width: 120px">
            <a-select-option v-for="(item,key) in fabricOrderDetail.cartInfoList"
                             :value="item.id" :key="item.id">
              {{ item.fabricInfo.fabricCode }}
            </a-select-option>
          </a-select>
        </label>
        <div style="width:530px;margin-top:10px;margin-bottom: 10px;">
          <a-textarea v-model="afterReson" placeholder="申请售后原因" :rows="4"
                      :auto-size="{ minRows: 3, maxRows: 5 }"/>
        </div>
        <!--<a-upload action=" https://api.nbyid.cn/mlcc/user/interface/uploadImage"
                  list-type="picture-card"
                  :file-list="fileList"
                  @preview="handlePreview" @change="handleChange">
            <div v-if="fileList.length < 3">
                <a-icon type="plus"/>
                <div class="ant-upload-text">
                    Upload
                </div>
            </div>
        </a-upload>-->
        <el-upload
            action="https://api.nbyid.cn/mlcc/user/interface/uploadImage"
            list-type="picture-card"
            :limit="1"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
            :on-success="handleSuccess"
            ref="upload">
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
        <div class="btn10" @click="submitAafter">提交订单</div>
      </div>
    </div>

  </div>
</template>

<script>
import {getAction} from "../../api/manage";
// @ is an alias to /src
import locale from 'ant-design-vue/es/date-picker/locale/zh_CN';

function getBase64(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = () => resolve(reader.result);
    reader.onerror = error => reject(error);
  });
}

export default {
  created() {
    this.getFabricDetail()
  },
  name: 'MyAfterSales',
  data() {
    return {
      cart: '', // 需要返修的购物车id
      dialogImageUrl: '',//上传的图片路径
      dialogVisible: false,
      autohor_token: localStorage.getItem("token"), //token
      fabricOrderDetail: {},// 面料订单详情
      cartDeatil: [],// 面料订单中的购物车列表
      url: {
        fabricDetail: "/cart/getFabricOrderDetail", // 面料订单详情
        afterOrder: '/Order/applicationAafter'// 面料订单申请售后
      },
      afterType: '1', // 售后类型
      afterReson: '',// 售后原因
      locale,
      previewVisible: false,
      previewImage: '',
      fileList: [],
    }
  },
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    //上传图片成功函数
    handleSuccess(response, file, fileList) {
      var result = response;
      this.dialogImageUrl = result.data;
    },

    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },

    // 获取面料订单详情
    getFabricDetail() {
      getAction(domain.publicUrl + this.url.fabricDetail, {
        'token': this.autohor_token, // token
        'orderSn': this.$route.query.order, // 选中的订单编号
      }).then(res => {
        if (res.data.code == '0') {
          this.fabricOrderDetail = res.data.data
          this.cartDeatil = res.data.data.cartInfoList
        }
      })
    },

    // 提交订单售后申请
    submitAafter() {
      getAction(domain.publicUrl + this.url.afterOrder, {
        'token': this.autohor_token,
        'orderSn': this.$route.query.order,
        'remark': this.afterReson,
        'afterType': this.afterType,
        'img': this.dialogImageUrl,
        'cart': this.cart
      }).then(res => {
        if (res.data.code == '0') {
          this.$message.success("提交成功")
          this.$router.push("/my-order")
        } else if (res.data.code == '-7') {
          this.$message.warning("此产品已经退款，不可提交")
        } else {
          this.$message.warning(res.data.msg)
        }
      })
    },

    selectTab: function (dataStr, i) {
      this[dataStr] = i
    },
    handleCancel() {
      this.previewVisible = false;
    },
    async handlePreview(file) {
      if (!file.url && !file.preview) {
        file.preview = await getBase64(file.originFileObj);
      }
      this.previewImage = file.url || file.preview;
      this.previewVisible = true;
    },
    handleChange({fileList}) {
      this.fileList = fileList;
    },
  },
  mounted() {
    // 切换页面时滚动条自动滚动到顶部
    window.scrollTo(0, 0);
  }
}
</script>

<style scoped lang="scss">
.roder-details {
  width: 80%;
  margin: 0 auto;
  background: #fff;
  margin-top: 20px;
  padding: 20px 35px;

  .btn10 {
    width: 112px;
    height: 40px;
    background-color: rgba(13, 221, 108, 1);
    border-radius: 3px;
    line-height: 40px;
    text-decoration: none;
    color: #fff;
    text-align: center;
    display: block;
  }

  .btns {
    display: flex;
    justify-content: space-between;
    height: 36px;
    align-items: center;
    margin-bottom: 50px;

    div {
      display: flex;
    }

    a.b1 {
      background-color: #393939;
      width: 122px;
      height: 36px;
      color: rgb(255, 238, 58);
      font-size: 15px;
      line-height: 36px;
      text-align: center;
      display: block;
      border-radius: 3px;
    }

    a.b2 {
      background-color: #393939;
      width: 90px;
      height: 36px;
      color: #fff;
      font-size: 15px;
      line-height: 36px;
      text-align: center;
      display: block;
    }

    a.b3 {
      background-color: rgba(242, 242, 242, 1);
      width: 90px;
      height: 36px;
      color: #444;
      font-size: 15px;
      line-height: 36px;
      text-align: center;
      display: block;
    }
  }

  .info {
    padding-top: 30px;

    .inputs {
      div {
        display: flex;
        margin-bottom: 10px;

        p {
          width: 112px;
          padding: 2px 2px 2px 24px;
          background-color: rgba(249, 249, 249, 1);
          font-size: 15px;
          color: #333;
          display: flex;
          height: 36px;
          align-items: center;
          margin: 0px !important;
        }

        span {
          width: 114px;
          padding: 2px 2px 2px 24px;
          background-color: rgba(255, 255, 255, 1);
          font-size: 15px;
          color: #333;
          display: flex;
          font-weight: 100;
          height: 36px;
          align-items: center;
          margin-left: 3px;
          border-width: 1px;
          border-style: solid;
          cursor: pointer;
          border-color: rgba(242, 242, 242, 1);

          &:hover {
            font-weight: 600;
            color: #fff;
            background-color: rgba(159, 159, 159, 1);
          }
        }

        b {
          width: 61px;
          cursor: pointer;
          text-align: center;
          background-color: rgba(249, 249, 249, 1);
          font-size: 15px;
          color: #333;
          display: flex;
          font-weight: 100;
          height: 36px;
          align-items: center;
          justify-content: center;

          &:hover {
            font-weight: 600;
            color: #fff;
            background-color: rgba(159, 159, 159, 1);
          }
        }
      }
    }

    .img12 {
      border-width: 1px;
      border-style: solid;
      border-color: rgba(242, 242, 242, 1);
      width: 193px;
      min-width: 193px;
      margin-right: 30px;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      align-items: center;

      & > p:nth-child(2) {
        background-color: #4d4d4d;
        color: rgb(255, 236, 112);
        line-height: 16px;
        font-size: 13px;
        padding: 5px 13px;
        margin-bottom: 6px;
      }

      & > p:nth-child(3) {
        background-color: #4d4d4d;
        color: rgb(255, 236, 112);
        line-height: 16px;
        font-size: 13px;
        padding: 5px 10px;
      }

      img {
        width: 153px;
        height: 158px;
        position: relative;
        top: -10px;
      }
    }

    .table-css {
      position: relative;

      .bz {
        width: 447px;
        height: 63px;
        background: inherit;
        background-color: rgba(255, 221, 202, 1);
        position: absolute;
        right: 0px;
        top: -63px;
        display: flex;
        align-items: center;
        justify-content: center;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        flex-direction: column;

        p {
          width: 100%;
          color: rgb(251, 8, 8);
          font-size: 13px;
          padding-left: 10px;
          margin-bottom: 0px;
          line-height: 16px;
        }
      }
    }

    .btn {

      border-width: 0px;
      width: 112px;
      height: 40px;
      background: inherit;
      background-color: rgba(13, 221, 108, 1);
      border: none;
      border-radius: 3px;
      -moz-box-shadow: none;
      -webkit-box-shadow: none;
      box-shadow: none;
      font-family: 'PingFangSC-Medium', 'PingFang SC Medium', 'PingFang SC';
      font-weight: 500;
      font-style: normal;
      font-size: 15px;
      text-align: center;
      display: block;
      color: #fff;
      line-height: 40px;
      margin-top: 25px;
      margin-bottom: 60px;
      cursor: pointer;
    }

    .price {
      color: rgb(38, 38, 38);
      font-size: 16px;
      padding: 2px 2px 2px 24px;
      font-weight: 700;

      span {
        color: rgb(215, 1, 1);
      }

      margin: 35px 0px;
    }

    .price1 {
      color: rgb(38, 38, 38);
      font-size: 16px;
      font-weight: 400;
      padding: 2px 2px 2px 24px;

      span {
        color: rgb(215, 1, 1);
      }

      margin: 35px 0px;
    }

    .text1 {
      width: 533px;
      height: 105px;
      padding: 3px 2px 3px 2px;
      font-family: 'ArialMT', 'Arial';
      font-weight: 400;
      font-style: normal;
      font-size: 13px;
      text-decoration: none;
      letter-spacing: normal;
      color: #000000;
      vertical-align: none;
      text-align: left;
      text-transform: none;
      background-color: #f9f9f9;
      border-color: transparent;
      resize: none;
      outline: none;
      padding: 10px;
    }

    .tabs {
      .tab {
        margin-bottom: 10px;
        display: flex;

        h5 {
          width: 112px;
          padding: 2px 2px 2px 24px;
          background-color: rgba(249, 249, 249, 1);
          font-size: 15px;
          color: #333;
          display: flex;
          height: 36px;
          align-items: center;
          margin: 0px !important;
          margin-right: 6px !important;
        }

        .tab-content {
          height: 36px;
          display: flex;

          p {
            border: 1px solid rgb(242, 242, 242);
            min-width: 100px;
            height: 36px;
            height: 36px;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 15px;
            color: #333;
            font-size: 15px;
            margin-right: 6px;

            cursor: pointer;

            b {
              display: none;
              font-weight: 700;
            }

            &.active {
              color: rgb(255, 236, 112);
              font-weight: 700;
              background-color: rgb(74, 74, 74);
            }

            &:hover {
              b {
                display: block;
              }

              span {
                display: none;
              }
            }
          }
        }
      }
    }

    h3.title {
      height: 30px;
      line-height: 30px;
      position: relative;
      font-size: 16px;
      color: #333;
      font-weight: 700;
      margin-bottom: 25px;

      &:after {
        position: absolute;
        height: 100%;
        width: 5px;
        position: absolute;
        left: -35px;
        top: 0px;
        background-color: rgba(74, 74, 74, 1);
        content: "";
      }
    }

    .title2 {
      width: 112px;
      padding: 2px 2px 2px 24px;
      font-size: 15px;
      color: #333;
      display: flex;
      height: 36px;
      align-items: center;
      margin: 0px !important;
      margin-bottom: 10px !important;
      font-weight: 700;
    }

    .list {
      margin-bottom: 20px;

      .list-div {
        display: flex;
        flex-wrap: wrap;

        div {
          width: 33.3%;
          display: flex;
          height: 36px;
          align-items: center;

          p {
            width: 112px;
            padding: 2px 2px 2px 24px;
            background-color: rgba(249, 249, 249, 1);
            font-size: 15px;
            color: #333;
            display: flex;
            height: 36px;
            align-items: center;
            margin: 0px !important;
          }

          span {
            width: calc(100% - 112px);
            padding: 2px 2px 2px 24px;
            font-size: 15px;
            color: #333;
            display: flex;
            height: 36px;
            align-items: center;

            &.b {
              font-weight: 700;
            }
          }
        }
      }
    }
  }
}
</style>
